package base.thread.syn;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author: my_code
 * @Create: 2020-12-08 18:48
 */
public class TestJUC {
    public static void main(String[] args) throws InterruptedException {
        //ArrayList<String> list = new ArrayList<String>();
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 5000; i++) {
            new Thread(() ->
                    list.add(Thread.currentThread().getName())
            ).start();
            //线程不安全
//            new Thread(() ->
//                    list.add(Thread.currentThread().getName())
//            ).start();
        }
        Thread.sleep(2000);

        System.out.println(list.size());
    }
}
